package middle

import (
	"context"
	"github.com/gin-gonic/gin"
	"gql3/constants"
	"gql3/graph/model"
)

func DataloaderMiddle() gin.HandlerFunc {
	return func(c *gin.Context) {
		ctx := context.WithValue(c.Request.Context(), constants.LoadersKey, &model.Loaders{
			UserById:          (&model.User{}).NewLoader(),
			UserExtraInfoById: (&model.UserExtraInfo{}).NewLoader(),
		})
		c.Request = c.Request.WithContext(ctx)
		c.Next()
	}

}
